package org.devknights.android.moneyeye.core.handlers;

import java.util.ArrayList;

import org.devknights.android.andlib.sms.SMSReader;
import org.devknights.android.andlib.sms.SMSUtil;
import org.devknights.android.R;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class UpdateHandler implements OnClickListener {
	private Activity activity;

	public UpdateHandler(Activity activity) {
		this.activity = activity;
	}

	public void onClick(View v) {
		ArrayList<String> smsList = new ArrayList<String>();
		SMSReader sr = SMSUtil.readSMS(activity, "inbox");

		while (sr.hasNext()) {
			smsList.add(0, "-----------" + sr.getString("address")
					+ "---------------\n" + sr.getString("body") + "\n");
			sr.next();
		}

		ListView smsListView = (ListView) activity.findViewById(R.id.SMSList);
		smsListView.setAdapter(new ArrayAdapter<String>(activity,
				android.R.layout.simple_list_item_1, smsList));
	}
}
